package com.police.activity;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.astrob.mapapi.core.PoiItem;
import com.police.R;

public class PoiTip extends LinearLayout {
	private Button callPoi;
	private TextView poiName;

	private TextView poiAddr;
	// 导航按钮
	private Button startNavi;
	private PoiItem mPoiItem;

	public PoiTip(Context context) {
		this(context, null);
	}

	public PoiTip(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater inflate = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflate.inflate(R.layout.poi_tip, this, true);
		initUI();
		addListener();
	}

	private void initUI() {
		poiName = (TextView) findViewById(R.id.poiTip_name);
		poiAddr = (TextView) findViewById(R.id.poiTip_addr);

		callPoi = (Button) findViewById(R.id.poiTip_call);

		startNavi = (Button) findViewById(R.id.poiTip_navi);
	}

	private void addListener() {
		poiName.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				
			}
		});

		poiAddr.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
			
			}
		});

		callPoi.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String tel = "";
				if (!mPoiItem.hasTel()){
					return ;
				}
				tel = mPoiItem.getTelList().get(0);
				Toast.makeText(PoiTip.this.getContext(), "你将拨打" + tel , Toast.LENGTH_LONG).show();
			}
		});

		startNavi.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(PoiTip.this.getContext(), "你按了导航按钮", Toast.LENGTH_LONG).show();
			}
		});
	}
	
	public void setData(PoiItem poiItem){
		mPoiItem = poiItem;
		
		poiName.setText(mPoiItem.getTitle());
		poiAddr.setText(mPoiItem.getSnippet());
		if (!mPoiItem.hasTel()){
			callPoi.setEnabled(false);
		}
	}
}
